//select.c
//gcc -Wall -O3 -o select select.c -I./include -L./lib -lmysqlclient

#include "me_random.h"
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include "mysql.h"
#include <string.h>

int main(int argc, char * argv[])
{

  MYSQL mysql;	//need a instance to init
  MYSQL_RES *res;
  //	MYSQL_ROW row;
  char query[512];
  int flag, i, num;	// connect the database
  //	int t;
  mysql_init(&mysql);
  //	void *p=malloc(512);
  //	memset(p,0,512);



  if (!mysql_real_connect(&mysql, "192.168.137.101", "tangchao", "yvhkfhvk", "test", 0, NULL, 0))
  {
    printf("Eror connecting to database: %s\n", mysql_error(&mysql));
  } else

    for (i=0; i < 10; i++)
    {
      //		sleep(1);
      num=random_me(101000000, 102000000);
      printf("%d\n", num);
      sprintf(query, "select * from tborderdetail where orderid=%d", num);
      //		strcpy(p,query);
      flag=mysql_real_query(&mysql, query, (unsigned int) strlen(query));

      if (flag)
      {
        printf("query failed!\n");
        return 0;
      } else
      {
        res=mysql_store_result(&mysql);	// store query result

        /***************************************************
        do not print query result

                                        while (row=mysql_fetch_row(res))
                        {
                                for(t=0;t<mysql_num_fields(res);t++)
                                {
                                        printf("%s ",row[t]);
                                }
                                printf("\n");
                        }

         ***************************************************/

        mysql_free_result(res);
      }
    }
  //	free(p);
  mysql_close(&mysql);
  return 0;
}
